package ClassesItemExtends;

import java.util.Dictionary;
import java.util.Hashtable;

import android.util.Log;

import Classes.EventRecord;
import Classes.KeyEventManager;
import Classes.EventExtends.SwitchEvent;


public class Luggage {

	Dictionary<String,ItemQty> dictComsumableItems=new Hashtable<String,ItemQty>();
	Dictionary<String,ItemQty> dictEquipments=new Hashtable<String,ItemQty>();
	Dictionary<String,ItemQty> dictPlotItems=new Hashtable<String,ItemQty>();
	
	public int amount=0;
	
	
	private static Luggage instance=null;
	public static Luggage getInstance(){
		
		if(instance==null){
			instance=new Luggage();
		}
		return instance;
	}

	private Luggage(){
		
	}
	
	

	public void addItem(ItemQty itemQty) {
		// TODO Auto-generated method stub

		Item item=itemQty.item;

		Dictionary<String,ItemQty> dict=getItemTypeDict(item);
		
		if(dict!=null){
			addItemTypeItemQty(dict,itemQty);
		}
		
	}

	private void addItemTypeItemQty(
			Dictionary<String, ItemQty> dict, ItemQty itemQty) {
		// TODO Auto-generated method stub
		ItemQty iq=dict.get(itemQty.item.id);
		if(iq==null){
			iq=itemQty;
		}else{
			iq.qty+=itemQty.qty;
		}
		
		dict.remove(itemQty.item.id);
		dict.put(iq.item.id, iq);
	}

	private Dictionary<String, ItemQty> getItemTypeDict(Item item) {
		// TODO Auto-generated method stub
		if(item instanceof ConsumableItem){
			return dictComsumableItems;
		}else if(item instanceof Equipment){
			return dictEquipments;
		}else if(item instanceof PlotItem){
			return dictPlotItems;
		}
		return null;
	}

	public void addMoney(int amount) {
		// TODO Auto-generated method stub
		this.amount+=amount;
	}

	public void addItem(ItemPriceCatalog priceCatalog) {
		// TODO Auto-generated method stub
		int amount=0;
		int count=priceCatalog.alItemPrice.size();
		for(int i=0;i<count;i++){
			ItemPrice ip=priceCatalog.alItemPrice.get(i);
			int qty=priceCatalog.alBuyAccount.get(i);
			ItemQty iq=new ItemQty(ip.item, qty);
			this.addItem(iq);
		}
		
	}

	
	
	
}
